<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>Template Controller - Fuel Documentation</title>
	<link href="../../assets/css/main.css" media="screen" rel="stylesheet" />
	<script type="text/javascript" src="../../assets/js/jquery-1.4.4.min.js"></script>
	<script type="text/javascript" src="../../assets/js/nav.js"></script>
	<script type="text/javascript" src="../../assets/js/highlight.pack.js"></script>
	<script type="text/javascript">
		$(function() {
			show_nav('general', '../../');
		});
		hljs.tabReplace = '    ';
		hljs.initHighlightingOnLoad();
	</script>
</head>
<body>

	<header>
		<h1>FUEL Documentation</h1>
	</header>

	<div id="main-nav"></div>

	<section id="content">
		<h2>Template Controller</h2>

		<h3>What is a template controller?</h3>

		<p>A Template Controller is an extension of the Base Controller which has template support built in using some pre-defined before() and after() methods. Basically it can be used to wrap
		your view in a layout with a header, footer, sidebar, etc.</p>

		<h3>Using the template controller</h3>

		<p>Like all Controllers you create a class in the <kbd>fuel/app/classes/controller</kbd> directory. They need to extend the <kbd>Controller_Template</kbd> class and are prefixed by default by "Controller_". Below is an example of the controller "example": </p>

<pre><code>class Controller_Example extends Controller_Template {

	public function action_index()
	{
		$this->template->title = 'Example Page';
		$this->template->content = View::factory('test/index', $data);
	}
}</code></pre>

		<h3>Example template</h3>

		<p>
			The template file is a great place to call up your JS, CSS, etc, structure your HTML and call view partials. It allows you to give your output
			structure. It is just a view file, by default the Template Controller will look here: <kbd>fuel/app/views/template.php</kbd>.
		</p>

<pre><code>&lt;!DOCTYPE html>
&lt;html>
&lt;head>
	&lt;meta charset="utf-8">
	&lt;title>&lt;?php echo $title; ?>&lt;/title>

	&lt;?php echo Asset::css('main.css'); ?>
&lt;/head>
&lt;body>
	&lt;div id="wrapper">
		&lt;h1>&lt;?php echo $title; ?>&lt;/h1>

		&lt;div id="content">
			&lt;?php echo $content; ?>
		&lt;/div>
	&lt;/div>
&lt;/body>
&lt;/html></code></pre>

        <h3>Changing the default template file</h3>

        <p>
            You can easily change the default <kbd>APPPATH/views/template.php</kbd> file to something different.<br/>
            You must set the public variable <kbd>$template</kbd> (note: you don't need .php extention here) to something different, example:
        </p>

<pre><code>class Controller_Example extends Controller_Template {

    public $template = 'template_admin';
    
    public function action_index()
    {
        $this->template->title = 'Example Page';
        $this->template->content = View::factory('test/index', $data);
    }
}</code></pre>
	</section>

	<section id="footer">
		<p>
			<a href="http://fuelphp.com">Fuel PHP</a> is released under the MIT license.<br />
			&copy; 2010 - 2011 Fuel Development Team
		</p>
	</section>

</body>
</html>